home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / basic / UDP_Chat.lha / UDPTest / UDP-Examples.readme < prev    next >
Encoding:
Text File  |  1998-04-23  |  7.5 KB  |  166 lines

  1.           
  2.  
  3.                          UDP Examples  
  4.  
  5.  Written by Anton Reinauer- 23/4/98
  6.  
  7.      These examples are useful for anyone who wants to write a internet 
  8. multi-user, fast reaction game (platformers, Doom clones etc), that by 
  9. their nature must have small communication delays (lags). These 
  10. programs differ from Paul Burkey's TCP examples in that they use the 
  11. UDP internet protocol instead of TCP for speed (TCP is ok for strategy 
  12. or turn based games as a slight lag is acceptable with them). UDP is 
  13. much faster, but unlike TCP there is no guarantee that your data packet 
  14. will get to it's destination (UDP is about 90% reliable); so you have 
  15. to write your communication code with this in mind.
  16.  
  17.      You need TCP-to-Blitz.lha from dev/basic on Aminet, and recompile 
  18. your Deflibs with bsdsocket.library1 in your amigalibs drawer in 
  19. Blitzlibs: . You'll obviously need an TCP/IP stack like Miami or AmiTCP 
  20. running (an Internet connection isn't necessary if you're just running 
  21. it locally).
  22.  
  23.    Minumum requirement: an A500 with some extra fast mem (to run the 
  24. TCP/IP stack in), and WB 2.0+. You have to turn overflow errors off in 
  25. the debugger options in Compiler Options.
  26.  
  27.    All four programs open UDP sockets (domain AF_INET, and type of 
  28. SOCK_DRAM). The first Send program (UDP_Send) just simply sends each 
  29. packet to the host address and port defined at the top of the program 
  30. (this could be different for every data packet). UDP_Receive binds it's 
  31. socket with bind_() to localhost at the port defined at the top of the 
  32. program (this port can't have an entry in Services though). Then it 
  33. just checks if any data is waiting on the socket and gets it.
  34.  
  35.    The second Send program (UDP_Send2) does things slightly 
  36. differently. It opens a socket and then does a connect_() to the port 
  37. on the appropriate host (defined at the top of the program). Then it 
  38. just uses send_() like in TCP, and all packets will be sent to the 
  39. connected socket. UDP_Receive2 does the same as UDP_Receive, and binds 
  40. the socket to the port, but because there's a TCP-like connection to 
  41. the sending host, it just uses recv_() to receive data.
  42.  
  43.    Just run UDP_Send and UDP_Receive (or UDP_Send2 and UDP_Receive2), 
  44. and type some letters into the Send window and hit return, and they 
  45. will appear in the receive window. To close the programs, hit the close 
  46. button in their window. Note: UDP_Send works with UDP_Receive2, and 
  47. vice-versa! 
  48.  
  49.    I haven't got the programs working as a Daemon yet- when I tried, it 
  50. opened three programs for every packet sent (and AmiTCP said it had got 
  51. into a loop)! It appears UDP works slightly differently than TCP, I 
  52. think your Daemon has to signal back to the TCP/IP stack that it's 
  53. running or something. I don't think you'll really need a UDP Daemon 
  54. anyhow, as you'll probably being doing peer-to-peer connections, rather 
  55. than using a Server. You could always use a small TCP Daemon, which puts 
  56. up a window, to ask the user if they want to play a game, which could 
  57. then run your game and exit.
  58.  
  59.    UDP_Chat is a simple IRC chat type program using UDP. The code is a 
  60. bit messy at the moment (and I've added some horrible hacks to Alvaro 
  61. Thompson's (once) nice font sensitive code :-) - Typical bloody games 
  62. programmer ;-) . I have to write more docs for it, but you should be 
  63. able to work out what it's doing. I've written it as a game 
  64. communication code test program.
  65.  
  66.    You have to have a TCP/IP stack running before you run UDP_Chat.
  67. Your host address is printed beside the Localhost button. You have to 
  68. give this address to the other person through IRC (and vice-versa), and
  69. then you type the address they give you in the Send To: gadget and hit
  70. return. You shouldn't have to change the port number gadget (unless
  71. you've got two of them running locally- the second one will be bound to
  72. a port number one number higher than the first- the port UDP_Chat is 
  73. bound to is printed up in the top-right corner). 
  74.   
  75.   The lastest version (V1.9), has the UDP_Funcs in a separate Include 
  76. (and have a bugfix in them). It checks wether packets have arrived at 
  77. their destination and resends them if they haven't (ie: no reply after a 
  78. certain time- 5 secs). After 5 resends it assumes the link is dead and the
  79. player is considered offline- it doesn't do it properly at the moment- it 
  80. needs bugfixing. It doesn't show the ping time for each player yet, only the
  81. time for the last packet.
  82.   It can act as a Server or a Client- if it receives a correct connection
  83. request, it becomes the Server, and can have up to 7 other players 
  84. online. If it logs into another program (that isn't already online as a 
  85. client, and has a spare player position) it will be logged in as a Client
  86. - note it will still send messages directly to all the other players, not
  87. through the Server. 
  88.   See above for logging into another UDP_Chat program. You can run up to
  89. 8 UDP_Chat programs locally for testing, and all can log into one acting 
  90. as a Server- they all get different port numbers.  
  91.   Then just type into the Send: gadget and hit return. Your words will 
  92. be echoed on the screen above and will be sent to any players online.
  93. If you can't connect to a host (it will tell you under the 
  94. Send To: gadget), you won't have your words echoed onscreen, and they 
  95. won't be sent. The numbers after R: and S: (received and sent), are 
  96. packet number, and the player the packet is sent or received from.
  97.   The Delay 1s button stops the program for 1 second, and the Delay 1m
  98. stops the program for 1 minute- this is for simulating lags or lost 
  99. links. The localhost button is for getting your local IP address if 
  100. you go online after you've started the program. 
  101.  
  102.   The Net Protocol Header defines the hex numbers that tell what each 
  103. packet is, so you can decode the data in each packet. I haven't fully
  104. documented the protocol on computer file yet, but it's pretty 
  105. self-explanatory. 
  106.   You'll notice I've put in some security measures, ie: it checks if the 
  107. packet has come from a logged-in host (rather than having a player number
  108. in the packet- saves data too), so it stops people sending fake messages
  109. to try and cheat. People could still send fake IP packets if they knew what
  110. they were doing, so I might put in a security number in each packet, that 
  111. is random for each connection between each of the players. Even basic 
  112. encryption might be needed as well. 
  113.    
  114.   It needs to have code put in for disconnecting, to tell the Server which
  115. will then inform the other players. Also each player needs to send out 
  116. a `heartbeat' if they haven't send a packet for 5 seconds, so other players
  117. know they're still online. The numbered buttons are to check the lag to 
  118. each player- not implemented yet. 
  119.  
  120.    See Paul Burkey's Net web page for more info on Internet game  
  121. connections: <http://www.sneech.demon.co.uk/netlink.html>
  122.    Also see the file included in this archive `Lag problems in Net games',
  123. it is a discussion from the Blitz-List on the problems caused by lags 
  124. in multiplayer games, and a couple of solutions to those problems.  
  125.  
  126.    Feel free to use these routines in your program; just give me and 
  127. Paul Burkey a mention in your credits :-)  And maybe a copy of your game
  128. if you think these routines are worth it :-)
  129.  
  130. Thanks to Paul Burkey for TCP_Funcs. 
  131.  
  132.         <paulb@sneech.demon.co.uk>
  133.  
  134.         <burkey@bigfoot.com>
  135.  
  136.         <http://www.sneech.demon.co.uk>
  137.  
  138.  
  139.  
  140. Alvaro Thompson for TCP_GUI
  141.  
  142.         <alvaro@enterprise.net>
  143.  
  144.  
  145.  
  146. and to Dr. Ercole Spiteri for TCP-to-Blitz.
  147.  
  148.         <ercole@maltanet.omnes.net>  
  149.  
  150.         <ercole@usa.net>    
  151.  
  152.  
  153.  
  154. Any questions/comments to:
  155.  
  156.         Anton Reinauer   <anton@ww.co.nz>
  157.  
  158.         <http://www.ww.co.nz/home/anton>
  159.  
  160.  
  161.  
  162.  
  163.  
  164.   
  165.  
  166.